<extend name="layout/edit" />

<block name="HEADER">
	<style type="text/css">
		input[name='ranges']{
			padding-right: 28px !important;
		}
	</style>
</block>

<block name="CONTENT">
    <control:form id="form"/>
</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
		ns.init = function(){
			form.on("removeSearchValue",'latlong',function(){
				form.setValue('latitude','');
				form.setValue('longitude','');
			});
		}
		
		//选择坐标
		ns.selectLatlong = function(){
			var filter = {
	            url: $.getModule('edit_selectLat'),
	            oid:"",
	            mode:1,
	            latitude: form.getValue('latitude'),
	            longitude: form.getValue('longitude'),
	        }
			function yesFn(index,obj){
				var latLng = $(".qq_maps_latLng span").text();
				if(!latLng){
					$.toast(0,'请点击地图选择经纬度！');
					return false;
				};
				var latLngs = String(latLng).split(',');
				form.setValue('latlong', String(latLngs[0]).substring(0,11) +";"+latLngs[1].substring(0,11));
				form.setValue('latitude',latLngs[0]);
				form.setValue('longitude',latLngs[1]);
				layer.close(index);
			}
	        $.openIframe(filter, "选择经纬度",['80%', '80%'],['确定'],yesFn);
		}
		
		//新增奖项
		ns.add = function(){
			var filter = {
	            url: $.getModule('edit_prize') ,
	            oid:"",
	            mode:1,
	            activity_id:form.getValue('id')
	        }
	        $.openIframe(filter, "新增",['320px', '90%']);
		}
		
		//编辑奖项
		ns.edit = function(){
			var selectedRow = form.$grids['termGrid'].getSelectedRows()[0];
	        var filter = {
	            url:$.getModule('edit_prize') ,
	            oid: selectedRow.id ,
	            mode:2,
	            activity_id:form.getValue('id')
	        }
	        $.openIframe(filter, "编辑",['320px', '90%']);
		}
		
		//移动
		ns.adjustSort = function(type){
			form.$grids['termGrid'].adjustSort(type);
		}
		
        //保存
        ns.save=function(){
    		form.save(1).then(function(res){
            	form.opener.grid.load();
            });
        }
        
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



